﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Ny.Ci.Core;
using Ny.Ci.Core.Configuration;
using Ny.Ci.Core.Web;
using System;
using System.Collections.Generic;
using System.Text;

namespace Ny.Ci.EntityFrameworkCore.EntityFrameworkCore
{

    /* This class is needed to run EF Core PMC commands. Not used anywhere else */
    public class CiDbContextFactory : IDesignTimeDbContextFactory<CiDbContext>
    {
        public CiDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<CiDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            CiDbContextOptionsConfigurer.Configure(
                builder,
                configuration.GetConnectionString(CiConsts.ConnectionStringName)
            );

            return new CiDbContext(builder.Options);
        }
    }
}
